<?php $this->pageTitle = 'Assign Ticket #' . $ticket->ticket_code; ?>
<?php
$this->breadcrumbs = array(
	'Tickets' => array('/admin/index'),
	'#' . $ticket->ticket_code => array('/admin/assign', 'ticket_code' => $ticket->ticket_code),
	'Assign Ticket'
);
?>
<div class="main-title no-border clearfix">
	<div class=" float-left">
		<h1>Ticket #<?php echo $ticket->ticket_code; ?></h1>
	</div>
	<div class="controls float-left">
		<a id="submitTicket" class="link-button with-icon" href="<?php echo $this->createUrl('admin/update', array('ticket_code' => $ticket->ticket_code)); ?>">
			<img src="/images/icons/fugue/report--pencil.png" />
			Update Ticket
		</a>
	</div>
	<div class="controls float-right">		
		<?php //if ($ticket->canBeEscalatedByUser(Yii::app()->user->id) && !$ticket->isClosed()): ?>
			<a id="btnEscalate" class="link-button red with-icon" href="<?php echo $this->createUrl('admin/escalate', array('ticket_code' => $ticket->ticket_code)); ?>">
				<img src="/images/icons/farmfresh/16x16/sort_ascending.png" />
				Escalate
			</a>
		<?php //endif; ?>
	</div>
</div>
<div class="flat_area">
    <div class="grid_16 relative">
		<div class="section highlighted">
			<div class="block">
				<h4><strong><?php echo $ticket->subject; ?></strong></h4>
				<p>Added by <span class="blue"><?php if ($ticket->created_by_user_id==null) echo $ticket->name; else echo $ticket->ticketUserCreate->username;  ?></span> about <span class="blue"><?php echo DateFormatter::ago($ticket->create_time); ?></span></p>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						
						/*array(
							'label' => 'Escalation Level',
							'value' => $ticket->getCurrentEscalationLevel() ? $ticket->getCurrentEscalationLevel() : 'Not escalated'
						), */
						array(
							'label' => 'Closed By',
							'value' => $ticket->closed_by_user_id,
						//	'visible' => $ticket->isClosed()
						),
						array(
							'label' => 'Type',
							'name' => 'ticket_type_id',
							'value' => function($data){
								$buffer = TicketType::model()->findByPk($data->ticket_type_id);
								return $buffer->name;
							}
						),
						/*
						array(
							'type' => 'raw',
							'label' => $ticket->getReferenceLabel(),
							'value' => $ticket->reference
						),
						*/
						array(
							'label' => 'Create Date',
							'type' => 'raw',
							'value' => date("d-M-Y G:i:A", strtotime($ticket->create_time))
						),
						)));
				?>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						'name',
						'email',
						'subject'
						)));
				?>
				<hr/>
				<strong>Description</strong><br/>
				<?php echo $ticket->summary; ?>
			</div>
		</div>
	</div>
	<div class="grid_10">
		<div class="section">
			<div class="block">
				<h2>Assign ticket</h2>
				<?php
				$form = $this->beginWidget('CActiveForm', array(
					'id' => 'ticket-create-form',
					'enableAjaxValidation' => false,
						));
				?>
				<div class="row buttons">
						Assign User:
						<?php echo $form->dropDownList($newUserHasTicket, 'user_id', CHtml::listData(User::model()->findAllByAttributes(array('agency_id'=>$ticket->agency_id)), 'id', 'name'), array('prompt' => 'Select a User') ); ?>
					<?php //endif; ?>
				</div>
				<div class="row buttons">
						Assign Team:
						<?php echo $form->dropDownList($newTicketTeamHasTicket, 'ticket_team_id', CHtml::listData(TicketTeam::model()->findAllByAttributes(array('agency_id'=>$ticket->agency_id)), 'id', 'name'), array('prompt' => 'Select a Team') ); ?>
					<?php //endif; ?>
				</div>
				<div class="row buttons">
					<?php echo CHtml::submitButton('Assign', array('class' => 'green')); ?>
				</div>
				<?php $this->endWidget(); ?>
			</div>
		</div>
    </div>
	<div class="grid_6">
		<?php if (!empty($ticket->escalations)): ?>
			<div class="section">
				<div class="block">
					<h2>Escalation History</h2>
					<div class="grid-view grey">
						<table class="items" width="100%">
							<?php foreach ($ticket->escalations as $escalation): ?>
								<tr>
									<td>
										<?php echo date("d M, Y @ G:iA", strtotime($escalation->escalation_time)); ?>
									</td>
									<td>
										<span class="blue">Escalated</span> to <span class="blue link"><?php echo $escalation->escalatedToUser->name; ?></span> <strong>(Level <?php echo $escalation->escalation_level; ?>)</strong>
									</td>
								</tr>
							<?php endforeach; ?>
						</table>
					</div>
				</div>
			</div>
		<?php endif; ?>
	</div>
</div>
<?php
$this->renderPartial('_dialog_escalate', array('ticket' => $ticket, 'escalation' => $escalation, 'ticketEscalationLevels' => $ticketEscalationLevels));
?>
